package com.yanqu.road.server.cmd.newmonopolymkt.res;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_NEW_MONOPOLY_MARKET_RES_GRAB_SEARCH_FROM_CROSS, desc = "资源搜索")
public class NewMonopolyMarketResGrabSearchFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.CrossNewMonopolyMarketResGrabSearchRespMsg msg = NewMonopolyMarketProto.CrossNewMonopolyMarketResGrabSearchRespMsg.parseFrom(packet.getBytes());
        if(msg.getRet() != 0){
            ret = msg.getRet();
            return;
        }
        ret = player.getModule(NewMonopolyMarketModule.class).searchFromCross(msg.getGuanYin(), msg.getPointList(0));

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_NEW_MONOPOLY_MARKET_RES_GRAB_SEARCH, NewMonopolyMarketProto.NewMonopolyMarketResGrabSearchRespMsg.newBuilder().setRet(ret));
        }
    }
}
